package com.twu.biblioteca;

import com.sun.corba.se.impl.interceptors.PINoOpHandlerImpl;

import java.util.ArrayList;

/**
 * Created with IntelliJ IDEA.
 * User: ysotirov
 * Date: 30/01/13
 * Time: 18:17
 * To change this template use File | Settings | File Templates.
 */
public abstract class Menu implements IMenu {
    ArrayList<String> OptionList = new ArrayList<String>();
    //ArrayList<MenuOption> Options = new ArrayList<MenuOption>();
    String titleMsg="";
    String selectOptionMsg = "";
    String invalidMsg = "";
    Biblioteca biblioteca;
    IOInterface ioHandler;

 //   public void executeOption(int opt){}
    public Menu (IOInterface ioHndl, Biblioteca bibl){
        ioHandler = ioHndl;
        biblioteca = bibl;
    }




    public void displayMenu(){
        ioHandler.queueMsg(titleMsg);
        for (int i=0; i<OptionList.size(); i++)
        ioHandler.queueMsg(OptionList.get(i));
        ioHandler.queueMsg(selectOptionMsg);
        ioHandler.Print();
    }


    @Override
    public void executeOption() {}

    public int getUserChoice(){
        int opt = ioHandler.getInput();
        if (!validInput(opt, OptionList))
        {
            ioHandler.queueMsg("Please input a valid option");
            ioHandler.Print();
            opt = getUserChoice();
        }
        return opt;
    }

    @Override
    public boolean validInput(int opt, ArrayList validList){
        if ((opt>0) && (opt<=validList.size())) return true;
        return false;
    }

}
